﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WindowsFormsApplication1
{
     public class Operations
    {
        List<Question> currentQuestions;
        Subject currentSubject;
        int currentQuestionIndex;
        public Operations(Subject s)
        {
            this.currentSubject = s;
            currentQuestions = s.TestQuestions;
            currentQuestionIndex = 0;
        }

        public void GenerateTest(int num)
        {
            Random rand = new Random();

                for (int i = 0; i < currentQuestions.Count; i++)
                {
                    int tempNum = rand.Next(i, currentQuestions.Count);
                    Question temp = currentQuestions[i];
                    currentQuestions[i] = currentQuestions[tempNum];
                    currentQuestions[tempNum] = temp;
                }
                if (num < currentQuestions.Count)
                {
                    int count = currentQuestions.Count;
                    List<Question> tempQuestions = new List<Question>();
                    for (int i = 0; i < num; i++)
                    {
                        tempQuestions.Add(currentQuestions[i]);
                    }
                    currentQuestions = tempQuestions;
                }
        }

        public Question GetQuestion()
        {
            if (currentQuestionIndex < currentQuestions.Count)
            {
                Question t = currentQuestions[currentQuestionIndex];
                currentQuestionIndex++;
                return t;
            }
            else
                return null;
        }

    }
}
